<template>
	<view>
		<uni-card class="uni-top" >
			<text class="uni-body">请注意文明提问，如果你的提问带有恶意信息，将会被禁止使用提问箱，并且提问信息将会被屏蔽</text>
		</uni-card>
		<uni-card title="提问箱" :extra="this.friendnickname" class="easyinputcss" >
			<uni-easyinput  type="textarea" autoHeight  v-model="easyinputvalue" placeholder="在此处描写你的问题"></uni-easyinput>
			<button type="primary" size="default" class="buttonsomething" @click="sendtheask">完成</button>
		</uni-card>
	</view>
</template>

<script>
	import $http from '@/common/api/request.js'
	export default {
		data() {
			return {
				easyinputvalue:"",
				friendId:0,
				friendnickname:"",
				rules: {
					//校验用户名:
					easyinputvalue: {
						rule: /^(?!\s+$).+/,
						msg: "哎呦你干嘛~哎呦~要提问还要什么都不输入"
					},
				}
			};
		},
		methods:{
			//校验规则:
			validate(key) {
				let bool = true;
				if (!this.rules[key].rule.test(this[key])) {
					uni.showToast({
						title: this.rules[key].msg,
						icon: "none"
					})
					bool = false;
					return bool;
				}
				return bool;
			},
			//提问箱
			sendtheask(){
				if(! this.validate("easyinputvalue")){
					return;
				}
				$http.request({
					url: "/sendquestion",
					method: "POST",
					data: {
						friendId: this.friendId,
						title:this.easyinputvalue
					}
				}).then((res) => {
					console.log(res);
					this.easyinputvalue = "";
				}).catch((err) => {
					console.log(err);
				})
			}
		},
		onLoad(e) {
			this.friendId = e.friendID;
			this.friendnickname ="向"+e.nickname+"匿名提问"
		}
	}
</script>

<style lang="scss">
.uni-body{
	
	color: #e0697f;
}
.uni-top{
	background-color: #faeef2;
}
.easyinputcss{
	background-color: rgba(248, 248, 250,0.85);
}
.buttonsomething{
	position: relative;
	left: 50%;
	top:20rpx;
	transform: translateX(-50%);
	line-height: 68rpx;
	font-size: 32rpx;
}
</style>
